#include "array.h"
#include "sparse.h"
#include "parser.h"
#include "vp.h"
#include <getopt.h>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[]){
    Array<vector*> s;
    perceptron vp;
    int bpm=1;
    float margin=0;
    int ktype=0;
    const char* modelfile="vpmodel";
    float param=2;
    int t=10;
    int option;
    const char* help="Usage: %s [ -b bags ] [ -g margin ] [ -k kernel ] [ -m modelfile ] [ -p param ] [ -t iterations ] trainset\n";

    while((option=getopt(argc,argv,"b:g:k:m:p:t:"))!=EOF){
        switch(option){
            case 'b': bpm=atoi(optarg); break;
            case 'g': margin=atof(optarg); break;
            case 'k': ktype=atoi(optarg); break;
            case 'm': modelfile=optarg; break;
            case 'p': param=atof(optarg); break;
            case 't': t=atoi(optarg); break;
            case '?': fprintf(stderr,help,argv[0]); exit(1); break;
        }
    }
    if(argv[optind]==0){
        fprintf(stderr,help,argv[0]);
        exit(1);
    }

    parser p(argv[optind]);
    p.parse(s);
    vp.set(ktype,param,margin,bpm);
    vp.train(s,t);
    vp.write(modelfile);
//    for(int i=0; i<s.size(); i++)
//        delete s[i];
    return 0;
}
